/**
 * 
 */
package com.feonix.designPattern.Adapter.sample3;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @CopyRight (c)1993-2017
 * @Project common_practice
 * @Comments 请输入该类的描述
 * @NameSpace com.feonix.designPattern.Adapter.sample3
 * @Author Feonixzw
 * @CreateDate 2018年1月25日
 */
public class FileProperties extends Properties implements FileIO {
	private Properties properties;

	public FileProperties() {
		properties = new Properties();
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.feonix.designPattern.Adapter.sample3.FileIO#readFromFile(java.lang.
	 * String)
	 */
	@Override
	public void readFromFile(String fileName) throws IOException {
		properties.load(new FileInputStream(new File(fileName)));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.feonix.designPattern.Adapter.sample3.FileIO#writeToFile()
	 */
	@Override
	public void writeToFile(String targetFileName) throws IOException {
		properties.store(new FileOutputStream(targetFileName), "written by feonix");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.feonix.designPattern.Adapter.sample3.FileIO#setValue(java.lang.
	 * String, java.lang.String)
	 */
	@Override
	public void setValue(String key, String value) throws IOException {
		properties.setProperty(key, value);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.feonix.designPattern.Adapter.sample3.FileIO#getValue(java.lang.
	 * String)
	 */
	@Override
	public String getValue(String key) throws IOException {
		return properties.getProperty(key);
	}

}
